package com.pipidan.blog.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pipidan.blog.dao.MemoryDao;
import com.pipidan.blog.entity.Memory;
import com.pipidan.blog.mapper.MemoryMapper;
import com.pipidan.blog.service.MemoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName: MemoryServiceImpl
 * @Description: 流年记业务层接口实现类
 * @Author ONESTAR
 * @Date: 2020/10/20 9:06
 * @QQ群：530311074
 * @URL：https://onestar.newstar.net.cn/
 * @Version 1.0
 */
@Service
public class MemoryServiceImpl implements MemoryService {
    @Autowired
    private MemoryMapper memoryMapper;
    @Override
//    @Cacheable(value = "memoryList",key = "'memory'")       // redis缓存
    public List<Memory> listMemory() {
        QueryWrapper<Memory> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        return memoryMapper.selectList(wrapper);
    }

    @Override
    public int saveMemory(Memory memory) {

        return memoryMapper.insert(memory);
    }

    @Override
    public Memory getMemory(Long id) {

        return memoryMapper.selectById(id);
    }

    @Override
    public int updateMemory(Memory memory) {

        return memoryMapper.update(memory,new QueryWrapper<>());
    }

    @Override
    public void deleteMemory(Long id) {
        memoryMapper.deleteById(id);
    }
}
